﻿@model OT.Areas.Admin.Models.States
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
    <h3 id="myModalLabel">State Create</h3>
</div>
<div class="modal-body">
    <div id="alert_modal">
        @Html.ValidationSummary()
    </div>
    <div class="form-horizontal" role="form">
        <div class="form-group">
            <div class="col-lg-15">
                <div id="divMsgCre"></div>
            </div>
        </div>
        <div class="form-group" id="divStateCode">
            <label class="col-lg-3 control-label">State Code</label>
            <div class="col-lg-5">
                <input class="form-control" type="text" placeholder="Enter State Code" id="StateCode">
            </div>
        </div>
        <div class="form-group" id="divStateName">
            <label class="col-lg-3 control-label">State Name</label>
            <div class="col-lg-5">
                <input class="form-control" type="text" placeholder="Enter State Name" id="StateName">
            </div>
        </div>
        <div class="form-group" id="divCountryName">
            <label class="col-lg-3 control-label">Country Name</label>
            <div class="col-lg-5">
                @Html.DropDownListFor(model => model.CountryID, new SelectList(Model.Countrys, "CountryID", "CountryName"), "---- Select -----", new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.CountryID)
            </div>
        </div>
    </div>
</div>
<div class="modal-footer">
    <button class="btn btn-default" type="submit" id="btnCreate"><i class="icon-cog"></i>Save</button>
    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class=""></i>Cancel</button>
</div>
<script type="text/javascript">
    $("#btnCreate").click(function (e) {
        var CountryID = $("#CountryID option:selected").val();
        var StateName = $("#StateName").val();
        var StateCode = $("#StateCode").val();
        e.preventDefault();
        if (StateName == '' || StateCode == '' || CountryID == 0) {
            showMsg('divMsgCre', 'Please Enter Value For Required Field', 'danger');
            (CountryID == 0) ? $('#divCountryName').addClass('has-error') : $('#divCountryName').removeClass('has-error');
            (StateName == '') ? $('#divStateName').addClass('has-error') : $('#divStateName').removeClass('has-error');
            (StateCode == '') ? $('#divStateCode').addClass('has-error') : $('#divStateCode').removeClass('has-error');
        }
        else {
            $.ajax({
                url: "/Admin/State/Create?StateCode=" + StateCode + "&StateName=" + StateName + "&CountryID=" + CountryID,
                type: "POST",
                success: function (result) {
                    if (result != "NotValid") {
                        $('#modalDiv').modal('hide');
                        showMsg('divMsgIndex', ' Record saved Sucessfully .', 'success');
                        loadPage(1, 10, '');
                    }
                    else {
                        showMsg('divMsgCre', 'Record Not Saved !!Error', 'danger');
                    }
                },
                error: function (data) {
                }
            });
        }
        return false;
    });
</script>
